/**
 * <p><b>Title:</b> NotifyBcManager.java </p>
 * @Package com.wondertek.oes.charge.service.manager
 */
package com.wondertek.poms.core.manager;

import com.wondertek.poms.dao.vo.BcSendVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.service.IProductInfoPackageService;
import com.wondertek.poms.dao.po.Content;
import com.wondertek.poms.dao.po.PrdCont;
import com.wondertek.poms.dao.po.PrdInfo;
import com.wondertek.poms.dao.po.ProductInfoPackage;
import com.wondertek.poms.core.feign.BcFeignClient;

import lombok.extern.slf4j.Slf4j;

/**
 * <p><b>NotifyBcManager Description:</b> 通知播控的业务类</p>
 * @author douzi
 * <b>DATE</b> 2020年12月24日 上午10:48:27
 */
@Slf4j
@Component
public class NotifyBcManager {
    @Autowired
    private IProductInfoPackageService productInfoPackageService;
    @Autowired
	private BcFeignClient bcFeignClient;
    
	/**
	 * <p><b>Title:</b> process</p>
	 * <p><b>Description:</b> 通知播控过程方法 是否先上后审 是:通知能力发布；发播控 否:发播控</p>
	 * @author douzi
	 * @param prdInfo
	 * @param vo
	 * @param prdCont
	 */
	public void process(PrdInfo prdInfo, Content c, PrdCont prdCont) {
		process(prdInfo, c, prdCont, 0);
	}
	
	/**
	 * <p><b>Title:</b> process</p>
	 * <p><b>Description:</b> 通知播控</p>
	 * @author douzi
	 * @param prdInfo
	 * @param vo
	 * @param prdCont
	 * @param playBillFlag 直播节目单更新标记 1:是 0:否
	 */
	public void process(PrdInfo prdInfo, Content c, PrdCont prdCont, int playBillFlag) {
		BcSendVo osdpVo = new BcSendVo();
		osdpVo.setAssetId(prdCont.getMmsId());
		osdpVo.setAssetName(c.getName());
		if(StringUtils.isNotBlank(c.getFormType())){
			osdpVo.setAssetType(NumberUtils.toInt(c.getFormType()));
		}
		osdpVo.setType(Integer.parseInt(c.getType()));
		osdpVo.setStatus(c.getStatus().intValue());
		osdpVo.setContentId(Long.parseLong(prdCont.getContentId()));
		osdpVo.setPrdContId(prdCont.getPrdContId());
		osdpVo.setPrdInfoId(prdInfo.getPrdInfoId());
		osdpVo.setPrdInfoName(prdInfo.getName());
		osdpVo.setProductSecondId(prdInfo.getProductInfoPackageId());
		if (prdInfo.getProductInfoPackageId() != null) {
			ProductInfoPackage pip = productInfoPackageService.get(prdInfo.getProductInfoPackageId());
			if (pip != null) {
				if (pip.getProductInfoPackageType() == null) {
					osdpVo.setScreenType(2);
				} else {
					if (pip.getProductInfoPackageType() == 2) {
						osdpVo.setScreenType(2);
					} else if (pip.getProductInfoPackageType() == 1) {
						osdpVo.setScreenType(1);
					}
				}
			}
		}
		osdpVo.setUpdateFields(c.getUpdateFields());
		osdpVo.setCpid(c.getCopyrightCpid());
		osdpVo.setPlayBillFlag(playBillFlag);
		
		ResultBean resultBean = bcFeignClient.syncBc(osdpVo);
		if ("0".equals(resultBean.getCode())) {
			log.info("主流程|通知播控|通知成功|媒资id:" + c.getAssetId() + "|内容id:" + c.getContentId() + "|playBillFlag:" + playBillFlag + "|vo:" + osdpVo.toString());
		} else {
			log.info("主流程|通知播控|通知失败|媒资id:" + c.getAssetId() + "|内容id:" + c.getContentId() + "|playBillFlag:" + playBillFlag + "|vo:" + osdpVo.toString());
		}
	}
}
